//https://leetcode.cn/problems/minimum-size-subarray-sum/
class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int left = 0, right = 0, currentSum = 0;
        int minLength = nums.size() + 1;

        while (right < nums.size()) {
            currentSum += nums[right];

            while (currentSum >= target) {
                minLength = min(minLength, right - left + 1);
                currentSum -= nums[left];
                left++;
            }

            right++;
        }

        return minLength == nums.size() + 1 ? 0 : minLength;
    }
};
